package com.dwxt.race.controller;

import com.dwxt.common.base.BaseResult;
import com.dwxt.race.service.UserRaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 报名信息管理
 */
@RequestMapping("/race/enterRace")
@RestController
public class RaceEnterController {

    @Autowired
    private UserRaceService userRaceService;
    //退款
    @PostMapping("/payBack")
    public BaseResult payBack(@RequestParam(required = true)Integer userRaceId) throws Exception {
           return userRaceService.payBack(userRaceId);
    }

    /**
     * 赛事报名审核
     * Status---1：成功    0：报名取消    2：待支付（审核通过）   3：待审核   4:审核未通过  5：支付失败
     * 参数只有2、4
     */
    @PostMapping("/raceConfirm")
    public BaseResult raceConfirm(@RequestParam(required = true) Integer userRaceId,
                                  @RequestParam(required = true) Integer status,
                                  @RequestParam(required = false) String msg){
        return userRaceService.confirmInfo(userRaceId,status,msg);
    }

    /**
     * 赛事报名详情
     */
    @RequestMapping("/userRaceList")
    public BaseResult selectUserRaceList(@RequestParam(required = true) Integer pageNum,
                                         @RequestParam(required = true)Integer pageSize,
                                         @RequestParam(required = false)Integer id,
                                         @RequestParam(required = false)String userName,
                                         @RequestParam(required = false)String  phone,
                                         @RequestParam(required = false)Integer  status

                                         ){
       return userRaceService.selectListByRaceId(pageNum,pageSize,id,userName,phone,status);
    }
    /**
     * 支付成功回调
     */
    @RequestMapping("/payForSuccess")
    public BaseResult payForSuccess(@RequestParam(required = true)String orderId){
       return userRaceService.payForSuccess(orderId);
    }

    /**
     * 15分钟超时支付失败
     */
    @RequestMapping("/timeoutPayBack")
    public BaseResult timeoutPayBack(@RequestParam(required = true)String orderId){
        return userRaceService.timeoutPayBack(orderId);
    }
}
